const baseUrl = 'http://121.89.205.189:3001/api'

export default function request (config) {
  let { url, method, data, header } = config
  method = method || 'GET'
  data = data || {}
  header = {
    'content-type': 'application/json',
    'token': '1111111'
  }
  // 显示加载中的动画
  uni.showLoading({
    title: '加载中',
  })
  return new Promise((resolve, reject) => {
    uni.request({
      url: baseUrl + url,
      method: method.toUpperCase(),
      data,
      header,
      success: (res) => {
        resolve(res)
      },
      fail: (error) => {
        reject(error)
      },
      complete: () => {
        // 取消加载动画
        uni.hideLoading()
      }
    })
  })
}